package com.bouncing.ball;

import java.util.Random;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.*;

public class DrawView1 extends View implements OnTouchListener {
	private Ball[] ball = new Ball[20];
	private Paint something;

	public DrawView1(Context context)
	{
		super(context);
		setFocusable(true);
		Random randomGenerator = new Random();
		for(int i = 0; i < 20; i++)
		{
			int randomx = randomGenerator.nextInt(409);
			int randomy = randomGenerator.nextInt(662);
			int randomvel = randomGenerator.nextInt(20) + 1;
			randomx = randomGenerator.nextInt(409);
			randomy = randomGenerator.nextInt(662);
			ball[i] = new Ball(randomx, randomy, randomvel, randomvel, 25, Color.RED, context, R.drawable.fsm_icon);
			ball[i].setid(i);
		}
		setFocusableInTouchMode(true);
		this.setOnTouchListener(this);
	}

	@Override
	public void onDraw(Canvas c){
		for(int i = 0; i < 20; i++)
		{
					ball[i].move(ball[i]);
		}
		something = new Paint();
		something.setColor(Color.RED);
		something.setAntiAlias(true);

		for(int i = 0; i < 20; i++)
		{
			c.drawBitmap(ball[i].getImage(), ball[i].getxCoord(), ball[i].getyCoord(), null);
		}
		invalidate();
	}

	public boolean onTouch(View v, MotionEvent event) {
		//ball1.setxCoord((int)event.getX());
		//ball1.setyCoord((int)event.getY());
		return true;
	}
}